import {Form,Input,Button} from "antd";
import api from "../../api";
import styles from './index.module.less';
import type { ILoginParams } from "../../types/api.ts"
import storage from "../../until/storage";
const Login = () => {
    const onFinish = async (val:ILoginParams) => {
      const res = await api.login(val)
      storage.set('token',res)
      window.location.href = '/'
    };
  return (
    <div className={styles.login}>
      <div className={ styles.loginWrapper }>
        <div className={styles.title}>系统登录</div>
        <Form
          name="basic"
          initialValues={{ remember: true }}
          onFinish={onFinish}
          autoComplete="off"
        >
          <Form.Item
            label="Username"
            name="username"
            rules={[{ required: true, message: "Please input your username!" }]}
          >
            <Input />
          </Form.Item>

          <Form.Item
            label="Password"
            name="password"
            rules={[{ required: true, message: "Please input your password!" }]}
          >
            <Input.Password />
          </Form.Item>

          <Form.Item label={null}>
            <Button type="primary" htmlType="submit" block >
              登录
            </Button>
          </Form.Item>
        </Form>
      </div>
    </div>
  );
};
export default Login;
